<template>
  <div class="all">
    <el-button
      type="primary"
      plain
      @click="createdAdd"
      size="mini"
      icon="el-icon-plus"
      >配置</el-button
    >

    <!-- 弹窗 -->
    <el-dialog
      title="配置"
      :visible.sync="addData.dialogVisibleAdd"
      :width="width"
      :before-close="handleClose"
      :modal="false"
    >
      <div style="width: 100%" v-if="ishsowparams">
        <div style="text-align: right">
          <el-button type="primary" size="mini" @click="innerVisible = true"
            >选择参数</el-button
          >
          <el-button type="primary" size="mini" @click="deleteselect"
            >删除选中</el-button
          >
        </div>
        <fl-parameter
          ref="flparameter"
          @deleteselectarr="deleteselectarr"
          :allinorselect="false"
          :paramarr="paramarr"
        ></fl-parameter>
        <el-dialog width="80%" :visible.sync="innerVisible" append-to-body>
          <fl-parameter
            @handleSelectionChange="handleSelectionChange"
            :allinorselect="true"
          ></fl-parameter>
          <span slot="footer">
            <el-button type="primary" size="mini" @click="transmit"
              >确定</el-button
            >
          </span>
        </el-dialog>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="peizhi" size="mini">确 定</el-button>
        <el-button @click="addData.dialogVisibleAdd = false" size="mini"
          >退 出</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  getSelectByCodeAndType, //用于添加租户管理员时选择租户后之间传回选择租户的角色：
} from "@/api/TenantAdministratorManagement";
import flParameter from "@/views/collection/base/flProductModel/modifi.vue";
import {
  bindparamsidquery,
  queryparameter,
  bindvaluedel,
} from "@/api/collection/base/flProductModel/index.js";
// 字典
// import dictionaries from '@/views/components/FLPage/dictionaries'
export default {
  data() {
    return {
      hasvalue: false,
      //滑块
      switchvalue: false,
      dialogImageUrl: "",
      dialogVisible: false,
      disabledBathch: false,
      disabled: false,
      // 租户管理员  租户-角色数据
      sysCompanyCodeRolesData: this.$parent.sysCompanyCodeRoles,
      //添加数据模型
      addData: {
        //弹窗控制
        dialogVisibleAdd: false,
        //数据字典
        diaDataAddDictionaries: [],
        //添加弹窗的数据模型
        diaDataAdd: [],
        //确定的disabled，
        mainDisabled: true,
        eventualData: undefined,
      },
      // selectData:[]
      selectOptions: [
        {
          id: 1,
          name: "微山自来水",
          children: [
            {
              id: 2,
              name: "幸福苑小区",
              children: [{ id: 3, name: "1号楼" }],
            },
          ],
        },
        {
          id: 4,
          name: "泗水县",
          children: [
            {
              id: 5,
              name: "花园小区",
              children: [
                { id: 6, name: "1号楼" },
                { id: 7, name: "2号咯" },
                { id: 8, name: "2号咯" },
                { id: 9, name: "2号咯" },
              ],
            },
            {
              id: 10,
              name: "荣盛小区",
            },
          ],
        },
      ],
      superiorData: "",
      // 组件类型
      modelType: "search",
      // 请求到的option
      searchOption: [],
      // 跨表请求option
      searchOptions: [],
      checked: false,
      // 备注  文本域
      textarea: "",
      // 返回的角色对象
      roleArr: [],
      // ishsowparams: false,
      innerVisible: false,
      //将要上传的参数集合
      paramarr: [],
      deletearr: [],
      //上传文件列表
      annexPath: "",
      //上传图片列表
      imgFiles: [],
    };
  },
  name: "peizhi",
  components: {
    flParameter,
  },
  computed: {},
  props: {
    //添加传过来的值
    diaDataAdd: {},
    optionsZi: {},
    searchOptionTable: {},
    getFindByTypeData: {},
    sysCompanyCodeRoles: {},
    multipleSelection: {},
    modData: {},
    ishsowparams: {
      type: Boolean,
      default: false,
    },
    width: {
      type: String,
      default: "760px",
    },
    superiorListOption: {},
  },
  mounted() {
    this.addData.diaDataAdd = JSON.parse(JSON.stringify(this.diaDataAdd));
    console.log(this.addData.diaDataAdd, "diaDataAdd");
  },
  methods: {
    //删除选中
    deleteselect() {
      let o = this.paramarr.length;
      let z = this.deletearr.length;
      if (this.hasvalue) {
        let arr = [];
        for (let i = 0; i < z; i++) {
          console.log(this.deletearr[i].id);
          arr = arr.concat(this.deletearr[i].id);
        }
        console.log(arr);
        bindvaluedel(arr).then((res) => {
          if (res.code === 20000) {
            this.del(o, z);
            this.$message({
              message: "删除成功",
              type: "success",
            });
          }
        });
      } else {
        if (o === z) {
          this.paramarr = [];
          this.deletearr = [];
        } else {
          this.del(o, z);
        }
        this.deletearr = [];
      }
    },
    del(o, z) {
      for (let i = 0; i < o; i++) {
        for (let j = 0; j < z; j++) {
          if (this.paramarr[i].id === this.deletearr[j].id) {
            this.paramarr.splice(i, 1);
          }
        }
      }
    },
    //确定传递选择参数
    transmit() {
      this.innerVisible = false;
    },
    // 获取子组件选择的数据
    handleSelectionChange(value) {
      this.paramarr = value;
    },
    deleteselectarr(value) {
      this.deletearr = value;
      console.log(this.deletearr, "deletearr");
    },
    // 角色
    sysRoleChange(newvalue) {
      const roleArrs = this.roleArr;
      var id = "";
      for (let index = 0; index < roleArrs.length; index++) {
        const element = roleArrs[index];
        id = roleArrs[index].id;
      }
      this.$emit("sysRoleId", id);
      console.log(id);
    },
    async sysCompanyCodeChange(value) {
      console.log(value, "duime");
      const res = await getSelectByCodeAndType(value);
      console.log(
        res,
        "子组件用于添加租户管理员时选择租户后之间传回选择租户的角色"
      );
      const roleObjs = res.data;
      if (roleObjs) {
        console.log(roleObjs);

        this.roleArr = roleObjs;
      } else {
        console.log("该租户没有对应的角色");
      }
    },

    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          this.addData.dialogVisibleAdd = false;
          done();
        })
        .catch((_) => {});
    },
    //搜索框内容传递给父元素
    createdAdd() {

      console.log(this.modData);
      let obj = {
        parameter: {},
        productParameter: {
          productId: this.modData.id,
        },
      };
      bindparamsidquery(this.modData.id).then((res) => {
        console.log(res, "09090999999999999990909090909");
      });
      queryparameter(1, 9999, obj).then((res) => {
        console.log(res, "res");
        if (res.data.list != "") {
          this.paramarr = res.data.list;
          this.hasvalue = true;
        } else {
        }
      });
      this.addData.dialogVisibleAdd = true;
      this.$nextTick(()=>{
        this.$refs['flparameter'].detailFlag=true
      })
      //清空value;
      for (let i = 0; i < this.addData.diaDataAdd.length; i++) {
        this.addData.diaDataAdd[i].value = "";
        this.addData.diaDataAdd[i].result = true;
      }
    },
    //添加-传给父组件，ajax
    peizhi() {
      console.log(this.paramarr, "coooo");
      console.log(this.modData.id);
      let arr = [];
      for (let i = 0; i < this.paramarr.length; i++) {
        arr = arr.concat(this.paramarr[i].id);
        // console.log(this.paramarr[i].parameterId);
      }
      console.log(arr, "arr");
      let productId = this.modData.id;
      this.$emit("peizhi", arr, productId);
    },
    //删除-传给父组件，ajax

    getSTime(val) {
      this.addData.diaDataAdd.createTime = val;
      // console.log(val)
    },
    //正则表达式
    BurExp(e, item, index) {
      if (this.addData.diaDataAdd[index].skipSign && e.target.value === "") {
        item.result = true;
      } else {
        let boolean = new RegExp(item.Exp).test(e.target.value);
        item.result = boolean;
        this.addData.diaDataAdd[index].result = boolean;
        console.log(item.result, 999);
      }
    },
  },
  created() {
    // this.getSelectData()
    this.getSelectByCodeAndTypeDatas();
  },
  watch: {
    optionsZi(newVal) {
      this.searchOption = newVal;
    },
    searchOptionTable(newVal) {
      this.searchOptions = newVal;
    },
    multipleSelection(newVal) {
      console.log(newVal, 3589);
      if ((newVal, length == 0)) {
        this.disabledBathch = false;
      } else {
        this.disabledBathch = true;
      }
      console.log(newVal, this.disabledBathch, 3589);
    },
  },
};
</script>
<style scoped src="@/styles/allCss.css"></style>
<style lang="scss" scoped>
.all {
  .is-plain {
    // width: 84px;
    // height: 34px;
    // /deep/.el-icon-plus{
    //   width: 18px;
    //   height: 18px;
    //   text-align: center;
    //   line-height: 18px;
    // }
  }
  .allDelete {
    // width: 110px;
    // /deep/.el-icon-delete{
    //   width: 18px;
    //   height: 18px;
    //   text-align: center;
    //   line-height: 18px;
    // }
  }
  display: inline-block;
  /deep/.el-dialog__body {
    display: flex;
    flex-wrap: wrap;
  }
  .list {
    .lister {
      height: 44px;
      width: 370px;
      .fon {
        text-align: right;
        margin-right: 14px;
        width: 99px;
      }
      .inb {
        .el-input {
          /deep/.el-input__inner {
            width: 210px;
            height: 30px;
          }
        }
        .el-select {
          /deep/.el-input__inner {
            width: 210px;
            height: 30px;
          }
        }
        .el-textarea {
          /deep/.el-textarea__inner {
            width: 210px;
            height: 60px;
          }
        }
      }
    }
    .is-circle {
      margin-left: 3px;
      padding: 0;
      color: #e69620;
      border: 0;
      /deep/.el-icon-warning {
        height: 14px;
        width: 14px;
      }
    }
    .font_color {
      font-size: 12px;
      padding-left: 100px;
      padding-top: 10px;
    }
  }
}
</style>
